import sys

raw=input()
[h,w]=[int(i) for i in raw.split(" ")]

matrix=[]
for _ in range(h):
    matrix.append(input().split(" "))

ret=[[0]*h for _ in range(w)]
t=min(h,w)
for i in range(t):
    for j in range(i,t):
        ret[i][j]=matrix[j][i]
        ret[j][i]=matrix[i][j]

if h>w:
    for i in range(h-w):
        for j in range(w):

            ret[j][w+i]=matrix[w+i][j]
elif h<w:
    for i in range(w-h):
        for j in range(h):
            ret[h+i][j]=matrix[j][h+i]

for i in ret:
    print(" ".join(i))

